﻿@model Alma.Models.ShopModel
@using System.Globalization
@{

    ViewContext.Controller.ViewBag.Breadcrumb.Enter("Points de vente", "Index", "Shop");
    ViewContext.Controller.ViewBag.Breadcrumb.Enter(Model.Name);

    var jss = new System.Web.Script.Serialization.JavaScriptSerializer();
}
<div class="fullcol">
@if (Model.ImgUrl != null)
{
    <img alt="Product Illustration" class="productImg" src="@Url.Content(Model.ImgUrl)" />
}
else
{
    <img alt="Product Illustration" class="productImg" src="@Url.Content("~/Content/images/unavailable.gif")" />
}

    <script type="text/javascript">
        var map = null;

        function LoadMap() {
            map = new Microsoft.Maps.Map(document.getElementById('bingMap'),
            {
                credentials: 'AkCZ5m1WEQHmCI_IGnizvsQwwuocz4MVzwE7AI5t7nO8yrqo-18MfLem2Jyq4F8p',
                enableClickableLogo: false,
                enableSearchLogo: false
            });

            var location = new Microsoft.Maps.Location(@Model.LocationX.ToString(CultureInfo.InvariantCulture),
                @Model.LocationY.ToString(CultureInfo.InvariantCulture));
            map.setView({ zoom: 16, center: location });

            map.entities.clear();
            var pushpin = new Microsoft.Maps.Pushpin(location, null); 
            var infobox = null;

            pushpinClick = Microsoft.Maps.Events.addHandler(pushpin, 'click', function() {
            
                if (infobox == null)
                {
                    var infoboxOptions = {title:@Html.Raw(jss.Serialize(Model.Name)), description:'@Model.Description',
                        offset:new Microsoft.Maps.Point(0,30), width:200, height:100};
                
                    infobox = new Microsoft.Maps.Infobox(location, infoboxOptions );    
                    Microsoft.Maps.Events.addHandler(infobox, 'entitychanged', function () { infobox = null; });
                    map.entities.push(infobox);
                    
                }
                else
                {
                    
                    map.entities.remove(infobox);
                    infobox = null;
                }
                //pushpin.setOptions({visible: false});

            });
            map.entities.push(pushpin); 
            

        }

        $(document).ready(function () {
            LoadMap();
        });

     </script>


     <div id="bingMapWrapper"><div id="bingMap"></div></div>

    <ul style="clear: right; float: right; list-style: none; margin: 10px 0 0 0; padding: 0;">

 
    <li style="font-size: 11px;">
        <div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=209740869069396&amp;xfbml=1"></script><fb:like href="" send="true" layout="button_count" width="150" show_faces="false" font="segoe ui"></fb:like>
    </li>
    
    <li style="font-size: 11px;">
        <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-lang="fr">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
    </li>
    <li><g:plusone size="medium"></g:plusone></li>
    </ul>

    <h1>@Model.Name
    <span class="stars">
    @{
        float asc = (float)Math.Round(Model.score * 2) / 2f;
        for (int i = 0; i < 5; i++)
        {
            var imgName = asc > 0 ? (asc > 0.5 ? "fav-on.png" : "fav-demi.png") : "fav-off.png";
            <!-- TODO: jquery clicking on stars to give a score to the product -->
            <img alt="fav" src="@Url.Content("~/Content/images/" + imgName)" />
            asc -= 1f;
        }
        @: <span class="commentNote">(<a href="#comments">@Model.reviews.Count commentaires</a>)</span>
    }
    </span>   
    </h1>
    <p>@Model.Description</p>
    <hr style="clear: left; border: 0; height: 1px;" />
    <h2>Coordonnées du point de vente</h2>
    
    <dl style="clear: left;">
    <dt>E-mail</dt> <dd>@Model.Email</dd>
    <dt>Téléphone</dt> <dd>@Model.Phone</dd>
    @if (@Model.Fax != null)
    {
    <dt>Fax</dt> <dd>@Model.Fax</dd>
    }
    <dt>Adresse</dt>
    <dd>@Model.Address<br />@Model.Zipcode @Model.Town<br />@Model.Country</dd>

    </dl>

    <h2>
        Dans ce magasin</h2>
    <ul class="products">
        @foreach (var product in Model.Products)
        {
            <li>
                <a href="@Url.Action("Show", "Product", new { id = product.ID })">
                <img src="@Url.Content(product.ImgUrl)" alt="@product.ImgUrl" />
                <span>@product.Name</span>
                @* <p>@product.Description</p> *@
                </a>
            </li>
        }
    </ul>
    <h2 id="comments">Commentaires clients</h2>
        @using (Html.BeginForm("AddReview", "Shop", FormMethod.Post, new { @encType = "multipart/form-data" }))
        {
            @Html.ValidationSummary(true)
            <fieldset>
                <legend>Ajouter un commentaire</legend>Note:<div class="editor-field">
                    @Html.DropDownListFor(model => model.reviewScore, (ViewData["drop"] as SelectList))
                    @Html.ValidationMessageFor(model => model.reviewScore)
                </div>
                Commentaire:<div class="editor-field">
                    @Html.HiddenFor(model => model.ID)
                    @Html.EditorFor(model => model.reviewText)
                    @Html.ValidationMessageFor(model => model.reviewText)
                </div>
                <input type="submit" value="Ajouter" />
            </fieldset>
        }
        <fieldset>
            <table>
                @foreach (var review in Model.reviews)
                {
                    <tr>
                        <td>
                            Par <strong>@review.Name_User</strong> le @review.Date<br />
                            @review.Text
                        </td>
                    </tr>
                }
            </table>
        </fieldset>
    
</div>
